#!/bin/sh /usr/share/dpatch/dpatch-run
## 01-growisofs-pioneer.dpatch
##
## DP: Fixes to fail closing session on some PIONEER DVD-RW drives

@DPATCH@

diff -Naurp dvd+rw-tools-7.1.orig/growisofs_mmc.cpp dvd+rw-tools-7.1/growisofs_mmc.cpp
--- dvd+rw-tools-7.1.orig/growisofs_mmc.cpp	2008-03-04 17:47:49.000000000 +0000
+++ dvd+rw-tools-7.1/growisofs_mmc.cpp	2008-04-01 09:01:20.000000000 +0000
@@ -1743,8 +1743,17 @@ void plus_rw_finalize ()
 	cmd[1] = 0x01;		// "IMMED"
 	cmd[2] = 0x02;		// "Close session"
 	cmd[9] = 0;
-	if ((err=cmd.transport()))
-	    sperror ("CLOSE SESSION",err);
+	
+	// it seems, that pioneer is a bit crappy
+	while (err=cmd.transport()) {
+	    if (SK(err)==0x2 && ASC(err)==0x04 && ASCQ(err)==0x07) {
+		    sperror ("CLOSE SESSION (but try to continue)",err);
+		    usleep(10000);
+	    } else {
+		    sperror ("CLOSE SESSION",err);
+		    break;
+	    }
+	}
 
 	if (wait_for_unit (cmd)) break;
  
